package cn.shentianlan.controller;

import cn.shentianlan.criteria.UserCriteria;
import cn.shentianlan.domain.dto.UserDTO;
import cn.shentianlan.domain.entity.User;
import cn.shentianlan.service.UserService;
import cn.shentianlan.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 陈俊源
 * @Description TODO
 * @Date 2021/4/10
 * @Version 1.0
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public Result login(UserDTO userDTO){
        Result result = userService.login(userDTO);
        return result;
    }

    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(UserDTO userDTO){
        Result result = userService.saveOrUpdate(userDTO);
        return result;
    }

    @RequestMapping("/getUserById")
    public Result getUserById(Long token){
        Result result = userService.getUserById(token);
        return result;
    }

    @RequestMapping("/deleteUserById")
    public Result deleteUserById(Long id){
        Result result = userService.deleteUserById(id);
        return result;
    }

    @RequestMapping("/list")
    public Result findUserByCriteria(UserCriteria criteria){
        Result result = userService.findUserByCriteria(criteria);
        return result;
    }
}
